home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / optconf.thor < prev    next >
Text File  |  1998-05-24  |  14KB  |  474 lines

  1. /*
  2.  * $VER: OptConf V1.10 (27.04.97)
  3.  * Shaun Downend <shaund@amiganut.demon.co.uk>
  4.  *         Optimise a conference in a BBS.
  5.  *
  6.  */
  7.  
  8. /* Optional configuration items */
  9.  
  10. repackxpk = 1   /* during optimisation XPK packed conferences are unpacked.
  11.                  * set this to 1 to repack, or 0 to not repack.
  12.                  */
  13.  
  14. /* End configuration */
  15.  
  16. scriptver = subword(sourceline(1), 4,1)
  17. scriptinfo = 'OptConf.thor 'scriptver' © Shaun Downend.'
  18.  
  19. /*!~ "Bit numbers for message flags" */
  20.  
  21. MDB_READ          =  0   /* Message is read. */
  22. MDB_REPLIED       =  1   /* Message is replied. */
  23. MDB_PRIVATE       =  2   /* Message is private. */
  24. MDB_TO_USER       =  3   /* Message is to the user. */
  25. MDB_FROM_USER     =  4   /* Message is from the user. */
  26. MDB_DELETED       =  5   /* Message is deleted. */
  27. MDB_UNRECOVERABLE =  6   /* Message is can not be undeleted. */
  28. MDB_KEEP          =  7   /* Keep message. Message will not be deleted during conference packing. */
  29. MDB_TO_ALL        =  8   /* Message is to all. (has no reciever) */
  30. MDB_XPK_TEXT      =  9   /* Message text is Xpk'ed. (Private flag) */
  31. MDB_MARKED        = 10   /* Message is marked.  */
  32. MDB_URGENT        = 11   /* Message is urgent.  */
  33. MDB_IMPORTANT     = 12   /* Message is important. */
  34. MDB_SUPERMARKED   = 13   /* Message will not be unmarked as long as this flag is set. */
  35.  
  36. CDF_NOT_ON_BBS   = '00008000'x  /* This conference is not on the bbs. */
  37. CDB_NO_XPK_METHOD       = 13    /* Don't use any xpk method. */
  38.  
  39. BDB_NO_XPK_METHOD      = 4   /* Don't use any xpk method. */
  40. GCB_NO_XPK_METHOD      = 3   /* Don't use any xpk method. */
  41.  
  42. /*~!*/
  43.  
  44. options results
  45. options failat 31
  46.  
  47. signal on syntax
  48. signal on halt
  49. signal on break_c
  50. signal on failure
  51.  
  52. /*!~ "Open Thor and BBSREAD ARexx ports" */
  53.  
  54. p=' '||address()||' '||show('P',,)
  55. if pos(' THOR.',p)>0 then
  56. thorport=word(substr(p,pos(' THOR.',p)+1),1)
  57. else
  58. do
  59.     say ('Thor has to be running to use this script!')
  60.     exit(0)
  61. end
  62.  
  63. if ~show('p', 'BBSREAD') then
  64. do
  65.     address command
  66.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  67.     'WaitForPort BBSREAD'
  68.     if rc ~= 0 then call errmsg('Couldn''t open BBSRead''s ARexx port.')
  69. end
  70.  
  71. address(thorport)
  72. 'VERSION STEM 'version
  73.  
  74. fullver = subword(version.THOR, 1, 1)
  75. version.thorver = substr(fullver, 1, index(fullver, '.') - 1)
  76. version.thorrev = compress(substr(fullver, index(fullver, '.') + 1), 'ß')
  77.  
  78. thorversion = version.thorver || '.' || version.thorrev
  79.  
  80. if thorversion < 2.5 then call errmsg('You need at least Thor 2.5 to run this script!')
  81.  
  82. /*~!*/
  83.  
  84. /*!~ "Get list of conference(s) to optimise" */
  85.  
  86. address(thorport)
  87.  
  88. 'currentsystem' CURRENT
  89. if(rc = 1) then call errmsg('CURRENTSYSTEM failed: No current system')
  90. if(rc = 30) then call errmsg('CURRENTSYSTEM failed: 'THOR.LASTERROR)
  91.  
  92. address BBSREAD 'getconflist bbsname "'CURRENT.BBSNAME'" stem' CONFLIST
  93. if(rc = 5) then call errmsg('GETCONFLIST failed: BBS not found')
  94. if(rc ~= 0) then call errmsg('GETCONFLIST failed: 'BBSREAD.LASTERROR)
  95.  
  96. 'requestlist instem' CONFLIST 'outstem' SELECTED 'multiselect dragselect title "Select conference(s) to optimise:"'
  97. if(rc = 5) then exit
  98. if(rc ~= 0) then call errmsg('REQUESTLIST failed: 'THOR.LASTERROR)
  99.  
  100. 'lockgui'
  101.  
  102. address(BBSREAD)
  103.  
  104. drop CONFDATA.
  105. drop BBSDATA.
  106. drop GLOBDATA.
  107.  
  108. /* Get System and Global XPK settings */
  109.  
  110. 'getbbsdata bbsname "'CURRENT.BBSNAME'" stem' BBSDATA
  111. if(rc =  5) then call errmsg('GETBBSDATA failed: BBS name not found')
  112. if(rc = 30) then call errmsg('GETBBSDATA failed: 'BBSREAD.LASTERROR)
  113.  
  114. 'getglobaldata stem' GLOBDATA
  115. if(rc = 30) then call errmsg('GETGLOBALDATA failed: 'BBSREAD.LASTERROR)
  116.  
  117. ptotal = 0
  118.  
  119. longest = 0
  120.  
  121. /* Work out information for progress indicator */
  122.  
  123. do i = 1 to SELECTED.COUNT
  124.  
  125.     'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'SELECTED.i'" stem' CONFDATA
  126.     if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  127.     if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  128.  
  129.     /* find the longest conference name to fix width of progress indicator */
  130.     if length(SELECTED.i) > longest then longest = length(SELECTED.i)
  131.  
  132.     /* find out if the conference is xpk packed, if so then this requires another step */
  133.     if CONFDATA.XPKMETHOD ~= '' then xpk = 10000
  134.     else
  135.     do
  136.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpk = 0
  137.         else
  138.         do
  139.             if BBSDATA.XPKMETHOD ~= '' then xpk = 10000
  140.             else
  141.             do
  142.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpk = 0
  143.                 else
  144.                 do
  145.                     if GLOBDATA.XPKMETHOD ~= ''  then xpk = 10000
  146.                     else
  147.                     do
  148.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpk = 0
  149.                     end
  150.                 end
  151.             end
  152.         end
  153.     end
  154.  
  155.     /* total of progress indicator is xpk + create conf (10000) + copy msgs (10000)
  156.      * + pack conf (10000) + delete msgs (10000) + delete conf (10000).
  157.      * 10000 is used (a large value) to reduce inaccuracies on division later on.
  158.      */
  159.     ptotal = ptotal + xpk + 60000
  160. end
  161.  
  162. longest = length('Copying messages in ') + longest + length('to ') + longest + length('.temp')
  163.  
  164. /* open and fix progress indicator width */
  165. call oprog(scriptinfo,ptotal,center('...Starting OptConf.thor...Initialising script...',longest,' '))
  166.  
  167. pcurrent = 0
  168.  
  169. 'bufmode copyback'      /* Turn on copyback mode  */
  170.  
  171. /*~!*/
  172.  
  173. /*!~ "Main loop" */
  174. do n = 1 to SELECTED.COUNT
  175.  
  176.     conference = SELECTED.n
  177.  
  178.     tempconf  = conference'.temp'
  179.  
  180.     call getmsginfo(conference) /* get msg numbers for selected conference */
  181.  
  182.     xpkpack = 0
  183.     /* is conference xpk packed? */
  184.  
  185.     if CONFDATA.XPKMETHOD ~= '' then xpkpack = 1
  186.     else
  187.     do
  188.         if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpkpack = 0
  189.         else
  190.         do
  191.             if BBSDATA.XPKMETHOD ~= '' then xpkpack = 1
  192.             else
  193.             do
  194.                 if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpkpack = 0
  195.                 else
  196.                 do
  197.                     if GLOBDATA.XPKMETHOD ~= ''  then xpkpack = 1
  198.                     else
  199.                     do
  200.                         if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpkpack = 0
  201.                     end
  202.                 end
  203.             end
  204.         end
  205.     end
  206.  
  207.     call uprog(window,pcurrent,'Creating temporary conference 'tempconf'...')
  208.  
  209.     pcurrent = pcurrent + 10000
  210.  
  211.     /* create temporary conference */
  212.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" set' c2x(CDF_NOT_ON_BBS)
  213.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  214.  
  215.     call copyconf(conference,tempconf) /* copy msgs from orig conf to temp conf */
  216.  
  217.     /*!~ "Delete messages in original conference" */
  218.     call uprog(window,pcurrent,'Deleting messages in 'conference)
  219.  
  220.     pstart = pcurrent
  221.  
  222.     if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  223.     do
  224.         pinc = 10000 %  (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  225.  
  226.         do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  227.  
  228.             drop OLDMSGDATA.
  229.  
  230.             if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  231.  
  232.             pcurrent = pcurrent + pinc
  233.  
  234.             'readbrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'datastem' OLDMSGDATA
  235.             if(rc ~= 0) then call bbsreaderr
  236.  
  237.             if ~bittst(OLDMSGDATA.FLAGS,MDB_DELETED) then /* is message already deleted? */
  238.             do
  239.                 'updatebrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'setdeleted'
  240.                 if(rc ~= 0) then call bbsreaderr
  241.             end
  242.         end
  243.         pcurrent = pstart + 10000 /* adjust to fix any inaccuracies in previous division :-) */
  244.     end
  245.     else /* conference is empty so skip */
  246.     do
  247.         pinc = pstart + 10000
  248.         call uprog(window,pcurrent)
  249.     end
  250.     /*~!*/
  251.  
  252.     /*!~ "Pack original conference" */
  253.  
  254.     call uprog(window,pcurrent,'Clearing 'conference'...')
  255.  
  256.     pcurrent = pcurrent + 10000
  257.  
  258.     'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  259.     if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  260.     /*~!*/
  261.  
  262.     call getmsginfo(tempconf) /* get msg numbers for temp conf */
  263.  
  264.     call copyconf(tempconf,conference) /* copy msgs from temp conf to orig conf */
  265.  
  266.     /*!~ "Delete temporary conference" */
  267.     call uprog(window,pcurrent,'Deleting 'tempconf'...')
  268.  
  269.     pcurrent = pcurrent + 10000
  270.  
  271.     'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  272.     if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
  273.  
  274.     /*~!*/
  275.  
  276.     /*!~ "Repack XPK packed conference" */
  277.     if repackxpk = 1 then
  278.     do
  279.         if xpkpack = 1 then
  280.         do  /* If conference was xpk-packed then pack it */
  281.             call uprog(window,pcurrent,'XPK Packing 'conference'...')
  282.  
  283.             pcurrent = pcurrent + 10000
  284.  
  285.             address(BBSREAD)
  286.             'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
  287.             if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
  288.  
  289.         end
  290.     end
  291.     /*~!*/
  292.  
  293. end
  294.  
  295. call uprog(window,pcurrent,'Complete.')
  296. do i = 1 to 600
  297. end
  298.  
  299. pcurrent = pcurrent + 10000
  300.  
  301. /*!~ "Notify completion, update conf window, cleanup" */
  302. address(thorport)
  303. 'updateconfwindow'
  304. 'unlockgui'
  305. address(bbsread)
  306. 'bufmode endcopyback'
  307. call cprog(window)
  308. address(thorport)
  309. 'requestnotify "OptConf.thor complete!"' '" _OK "'
  310. if(rc = 30) then say THOR.LASTERROR
  311.  
  312. exit
  313. /*~!*/
  314.  
  315. /*~!*/
  316.  
  317. /*!~ "Copy all messages from one conference to another conference " */
  318. copyconf:
  319.  
  320. parse arg fromconf,toconf
  321.  
  322. call uprog(window,pcurrent,'Copying messages in 'fromconf 'to 'toconf)
  323.  
  324. pstart = pcurrent
  325.  
  326. if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
  327. do
  328.     pinc = 10000 % (CONFDATA.LASTMSG -  CONFDATA.FIRSTMSG)
  329.  
  330.     do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
  331.  
  332.         drop MSGTAGS.
  333.         drop MSGDATA.
  334.  
  335.         if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
  336.  
  337.         pcurrent = pcurrent + pinc
  338.  
  339.         'readbrmessage "'CURRENT.BBSNAME'"' '"'fromconf'"' i 'headstem' MSGTAGS 'textstem' MSGTAGS 'datastem' MSGDATA
  340.         if(rc ~= 0) then call bbsreaderr
  341.  
  342.         if ~bittst(MSGDATA.FLAGS,MDB_DELETED) | ~bittst(MSGDATA.FLAGS,MDB_UNRECOVERABLE) then
  343.         do
  344.             exargs = ''
  345.             if ~bittst(MSGDATA.FLAGS,MDB_MARKED)   then exargs = exargs || ' DONTMARKMESSAGE'
  346.             if bittst(MSGDATA.FLAGS,MDB_PRIVATE)   then exargs = exargs || ' PRIVATE'
  347.             if bittst(MSGDATA.FLAGS,MDB_READ)      then exargs = exargs || ' READ'
  348.             if bittst(MSGDATA.FLAGS,MDB_URGENT)    then exargs = exargs || ' URGENT'
  349.             if bittst(MSGDATA.FLAGS,MDB_IMPORTANT) then exargs = exargs || ' IMPORTANT'
  350.  
  351.             'writebrmessage "'CURRENT.BBSNAME'"' '"'toconf'" stem' MSGTAGS exargs
  352.             if(rc ~= 0) then call bbsreaderr
  353.  
  354.             msgnr = result
  355.  
  356.             exargs = ''
  357.  
  358.             if bittst(MSGDATA.FLAGS,MDB_KEEP)    then exargs = exargs || ' SETKEEP'
  359.             if bittst(MSGDATA.FLAGS,MDB_SUPERMARKED) then exargs = exargs || ' SETSUPERUNREAD'
  360.             if bittst(MSGDATA.FLAGS,MDB_REPLIED) then exargs = exargs || ' SETREPLIED'
  361.  
  362.             if MSGDATA.HAZELEVEL ~= 0 then exargs = exargs || ' HAZELEVEL ' || MSGDATA.HAZELEVEL
  363.  
  364.             if exargs ~= '' then 'updatebrmessage "'CURRENT.BBSNAME'"' '"'toconf'"' msgnr exargs
  365.             if(rc ~= 0) then call bbsreaderr
  366.  
  367.         end
  368.         /*
  369.         else say 'Message deleted or unrecoverable'
  370.         */
  371.     end
  372.     pcurrent = pstart + 10000 /* adjust for any inaccuracies in previous division :-) */
  373. end
  374. else /* conference is empty so skip it */
  375. do
  376.     pinc = pstart + 10000
  377.     call uprog(window,pcurrent)
  378. end
  379.  
  380. return
  381. /*~!*/
  382.  
  383. /*!~ "Get message numbers for a conference" */
  384. getmsginfo:
  385. parse arg conf
  386.  
  387. drop CONFDATA.
  388.  
  389. 'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'conf'" stem' CONFDATA
  390. if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
  391. if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
  392.  
  393. return
  394. /*~!*/
  395.  
  396. /*!~ "Progress indication" */
  397.  
  398. /*!~ "Open progress indicator" */
  399. oprog:
  400. parse arg ptitle,ptotal,ptxt
  401. address(thorport)
  402. 'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"'
  403. if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
  404. else window = result
  405. return
  406. /*~!*/
  407.  
  408. /*!~ "Update progress indicator" */
  409. uprog:
  410. parse arg pwindow,pcurrent,ptxt
  411. /*
  412. say 'current 'pcurrent
  413. */
  414. if ptxt = '' then ptxt = ''
  415. else ptxt = 'pt ' || '"'ptxt'"'
  416. address(thorport)
  417. 'updateprogress req' pwindow 'current' pcurrent ptxt
  418. if(rc~=0) then signal cleanup
  419. return(0)
  420. /*~!*/
  421.  
  422. /*!~ "Close Progress indicator" */
  423. cprog:
  424. parse arg pwindow
  425. address(thorport)
  426. 'closeprogress req' pwindow
  427. return
  428. /*~!*/
  429.  
  430. /*~!*/
  431.  
  432. /*!~ "Error handling" */
  433. break_c:
  434.  
  435. call errmsg('User break!')
  436.  
  437. error:
  438. halt:
  439. failure:
  440.  
  441. if rc ~= 0 then call errmsg('+++ Line 'sigl' returned 'rc': 'errortext(rc))
  442.  
  443. cleanup:
  444.  
  445. address(bbsread)
  446. 'bufmode endcopyback'
  447. if window ~= 'WINDOW' then call cprog(window)
  448. address(thorport)
  449. 'unlockgui'
  450. exit(0)
  451.  
  452. errmsg:
  453. parse arg msgtxt
  454. address(thorport)
  455. 'requestnotify "'msgtxt'"' '" _OK "'
  456. if(rc = 30) then say THOR.LASTERROR
  457. signal cleanup
  458. return
  459.  
  460. bbsreaderr:
  461. address(bbsread)
  462. 'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
  463. if(rc ~= 0) then
  464. do
  465.     address(thorport)
  466.     'requestnotify "CONFIGCONF failed: 'BBSREAD.LASTERROR'\nFailed to delete temporary conference."' '" _OK "'
  467. end
  468. address(thorport)
  469. 'requestnotify "BBSRead Error: 'BBSREAD.LASTERROR'\nThere appears to be a problem with the database.\nPlease repair the database before running this script.\nSystem    : 'CURRENT.BBSNAME'\nConference: 'fromconf'\nMessage no: 'i'."' '" _OK "'
  470. signal cleanup
  471. return
  472. /*~!*/
  473.  
  474.